#pragma once

#include "d3dUtil.h"
//class PhysicsBox;
//#include "PhysicsObjects.h"

struct CollisionBox //An simple collision box;
{
	D3DXVECTOR3 Position;
	D3DXVECTOR3 HalfVector;
	std::vector<D3DXVECTOR3> Points;

	CollisionBox(): Position(0,0,0), HalfVector(0,0,0)
	{
		for(int i = 0; i < 16; i++)
		{
			Points.push_back(D3DXVECTOR3(0,0,0));
		}
	}

	CollisionBox(D3DXVECTOR3 nPosition, D3DXVECTOR3 nHalfVector)
	{
		Position = nPosition;
		HalfVector = nHalfVector;
		//To make sure the half vector is a positive vector
		if(nHalfVector.x < 0)
		{
			nHalfVector.x *= -1;
		}
		if(nHalfVector.y < 0)
		{
			nHalfVector.y *= -1;
		}
		if(nHalfVector.z < 0)
		{
			nHalfVector.z *= -1;
		}
		
		// 1, 1, 1
		Points.push_back(D3DXVECTOR3(nHalfVector.x, nHalfVector.y, nHalfVector.z));

		// -1, -1, 1
		Points.push_back(D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, nHalfVector.z));

		// 1, -1, 1
		Points.push_back(D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, nHalfVector.z));

		// -1, 1, 1
		Points.push_back(D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, nHalfVector.z));

		// 1, 1, -1
		Points.push_back(D3DXVECTOR3(nHalfVector.x, nHalfVector.y, -nHalfVector.z));

		// 1, -1, -1
		Points.push_back(D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, -nHalfVector.z));

		// -1, 1, -1
		Points.push_back(D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, -nHalfVector.z));

		// -1, -1, -1
		Points.push_back(D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, -nHalfVector.z));

		//Push them back again, for rotation purposes
		//There has GOT to be a better way than this
		Points.push_back(D3DXVECTOR3(nHalfVector.x, nHalfVector.y, nHalfVector.z));
		Points.push_back(D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, nHalfVector.z));
		Points.push_back(D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, nHalfVector.z));
		Points.push_back(D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, nHalfVector.z));
		Points.push_back(D3DXVECTOR3(nHalfVector.x, nHalfVector.y, -nHalfVector.z));
		Points.push_back(D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, -nHalfVector.z));
		Points.push_back(D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, -nHalfVector.z));
		Points.push_back(D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, -nHalfVector.z));
	}

	void InitBox(D3DXVECTOR3 nHalfVector)
	{
		if(Points.size() > 0)
			Points.clear();

		if(Points.size() == 0)
		{
			// 1, 1, 1
			Points.push_back(D3DXVECTOR3(nHalfVector.x, nHalfVector.y, nHalfVector.z));

			// -1, -1, 1
			Points.push_back(D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, nHalfVector.z));

			// 1, -1, 1
			Points.push_back(D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, nHalfVector.z));

			// -1, 1, 1
			Points.push_back(D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, nHalfVector.z));

			// 1, 1, -1
			Points.push_back(D3DXVECTOR3(nHalfVector.x, nHalfVector.y, -nHalfVector.z));

			// 1, -1, -1
			Points.push_back(D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, -nHalfVector.z));

			// -1, 1, -1
			Points.push_back(D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, -nHalfVector.z));

			// -1, -1, -1
			Points.push_back(D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, -nHalfVector.z));

			//Push them back again, for rotation purposes
			//There has GOT to be a better way than this
			Points.push_back(D3DXVECTOR3(nHalfVector.x, nHalfVector.y, nHalfVector.z));
			Points.push_back(D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, nHalfVector.z));
			Points.push_back(D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, nHalfVector.z));
			Points.push_back(D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, nHalfVector.z));
			Points.push_back(D3DXVECTOR3(nHalfVector.x, nHalfVector.y, -nHalfVector.z));
			Points.push_back(D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, -nHalfVector.z));
			Points.push_back(D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, -nHalfVector.z));
			Points.push_back(D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, -nHalfVector.z));
		}
		else
		{
						// 1, 1, 1
			Points[0] = (D3DXVECTOR3(nHalfVector.x, nHalfVector.y, nHalfVector.z));

			// -1, -1, 1
			Points[1] = (D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, nHalfVector.z));

			// 1, -1, 1
			Points[2] = (D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, nHalfVector.z));

			// -1, 1, 1
			Points[3] = (D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, nHalfVector.z));

			// 1, 1, -1
			Points[4] = (D3DXVECTOR3(nHalfVector.x, nHalfVector.y, -nHalfVector.z));

			// 1, -1, -1
			Points[5] = (D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, -nHalfVector.z));

			// -1, 1, -1
			Points[6] = (D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, -nHalfVector.z));

			// -1, -1, -1
			Points[7] = (D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, -nHalfVector.z));

			//Push them back again, for rotation purposes
			//There has GOT to be a better way than this
			Points[8] = (D3DXVECTOR3(nHalfVector.x, nHalfVector.y, nHalfVector.z));
			Points[9] = (D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, nHalfVector.z));
			Points[10] = (D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, nHalfVector.z));
			Points[11] = (D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, nHalfVector.z));
			Points[12] = (D3DXVECTOR3(nHalfVector.x, nHalfVector.y, -nHalfVector.z));
			Points[13] = (D3DXVECTOR3(nHalfVector.x, -nHalfVector.y, -nHalfVector.z));
			Points[14] = (D3DXVECTOR3(-nHalfVector.x, nHalfVector.y, -nHalfVector.z));
			Points[15] = (D3DXVECTOR3(-nHalfVector.x, -nHalfVector.y, -nHalfVector.z));

		}
	}

	void SetPosition(D3DXVECTOR3 nPosition)
	{
		Position = nPosition;
	}
};

struct ObjectOrientedBoundingBox : public CollisionBox
{
	D3DXVECTOR3 angles;
	D3DXMATRIX rotMat;

	ObjectOrientedBoundingBox() : CollisionBox()
	{
		angles = D3DXVECTOR3(0,0,0);
		rotMat = D3DXMATRIX(1,0,0,0,
							0,1,0,0,
							0,0,1,0,
							0,0,0,1);
	}

	ObjectOrientedBoundingBox(D3DXVECTOR3 nPosition, D3DXVECTOR3 nHalfVector, D3DXVECTOR3 nAngles)
		: CollisionBox(nPosition, nHalfVector)
	{
		angles = nAngles;
		D3DXMatrixRotationYawPitchRoll(&rotMat,angles.x, angles.y, angles.z);
	}

	void Update(void)
	{
		D3DXMatrixRotationYawPitchRoll(&rotMat,angles.x, angles.y, angles.z);
	}

	void SetAngles( D3DXVECTOR3 nAngles)
	{
		angles = nAngles;
	}
};

struct CollisionSphere
{
	D3DXVECTOR3 Position;
	float Radius;

	CollisionSphere(): Position(0,0,0)
	{
		Radius = 0;
	}

	CollisionSphere(D3DXVECTOR3 nPosition, float nRadius)
	{
		Position = nPosition;
		Radius = nRadius;
	}

};
